function ekf_test(caseCfg)

resultPath = fullfile(caseCfg.parentpath,'result',caseCfg.caseName);
if ~isfolder(resultPath)
    mkdir(resultPath);
else
    % clearFolder(resultPath)
end
%% signal source

sigCfg.type = caseCfg.type;
sigCfg.x0 = caseCfg.x0;
sigCfg.numSamples = caseCfg.numSamples;
sigCfg.para = caseCfg.alpha;
sigCfg.snrDB = caseCfg.snrDB;

[y,x] = chaos_generator(sigCfg);

%% EKF
ekfCfg.type = caseCfg.type;
ekfCfg.numSamples = caseCfg.numSamples;
ekfCfg.para = caseCfg.alpha;
ekfCfg.Q = caseCfg.Q;               % 过程噪声协方差（经验调整）
ekfCfg.R = caseCfg.snrDB;         % 测量噪声协方差（由SNR计算）
[x_est,gains] = chaos_ekf(y,ekfCfg);

%% 误差计算
Npre = min(50,floor(caseCfg.numSamples/8));
[mse,evm] = cal_evaluation_metrics(x_est(Npre+1:end), x(Npre+1:end));
result.msedB = pow2db(mse);
result.evmdB = pow2db(evm);
fprintf('MSE: %.1fdB, EVM: %.1fdB\n', result.msedB, result.evmdB);

%% 可视化对比
fig = figure('Visible','off');
subplot(2,2,1);
plot(y, 'LineWidth',0.5);hold on;
plot(x, 'LineWidth',1.5);
title('origin signal');
grid on;

% subplot(2,2,2);
% title('origin signal with noise');
% grid on;

subplot(2,2,3);
plot(x_est, 'r', 'LineWidth',1.5);
title('kalman filtered');
grid on;

subplot(2,2,4);
plot(gains, 'r', 'LineWidth',1.5);
title('kalman gain');
grid on;

exportgraphics(fig,fullfile(resultPath,'test1.jpg'));
close(fig);

print_json(result,fullfile(resultPath,'result.json'));

% %% 局部细节对比
% fig = figure('Visible','off');
% plot(x(200:240), 'b-o'); hold on;
% plot(x_est(200:240), 'r-s');
% legend('x', 'x_{est}');
% % title('局部波形对比');
% grid on;
% exportgraphics(fig,'test2.jpg');
% close(fig);
end